package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableAreaInfoDto;
import com.yxy.dto.ValidationGroups;
import com.yxy.service.TableAreaInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.text.ParseException;

/**
 * @author huangxinrong
 * 地区管理
 */
@RestController
@Slf4j
@RequestMapping("/tableAreaInfo")//必须要加
public class TableAreaInfoController {

  @Autowired
  private TableAreaInfoService tableAreaInfoService;

  // 获取地区列表
  @Pagingable//添加分页
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TableAreaInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.getlist(pojo));
    return restResponse;
  }



  // 获取地区列表不分页
    @PostMapping("/listNoPage")
  public RestResponse getListNoPage(@RequestBody TableAreaInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.getListNoPage(pojo));
    return restResponse;
  }



  // app获取地区列表不分页
  @PostMapping("/appListNoPage")
  public RestResponse appListNoPage(@RequestBody TableAreaInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.appListNoPage(pojo));
    return restResponse;
  }


  //修改地区信息
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid  TableAreaInfoDto pojo) throws BusinessException, ParseException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.modify(pojo));
    return restResponse;
  }

  //新增地区信息
  @PostMapping("/create")
  public RestResponse create(@RequestBody TableAreaInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.save(pojo));
    return restResponse;
  }

  //根据id删除地区类型信息
  @PostMapping("/delete")
  public RestResponse delete(@RequestBody @Valid  TableAreaInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableAreaInfoService.delete(pojo.getId().toString()));
    return restResponse;
  }
}
